package com.ttbj.controller.owner;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ttbj.core.util.StringUtil;
import com.ttbj.product.api.OwnerFacade;
import com.ttbj.product.bean.dto.OwnerDto;
import com.ttbj.product.bean.dto.ViewData;
import com.ttbj.util.Assert;
import com.ttbj.util.ResultUtil;
import com.ttbj.util.ViewModelUtil;

@Controller
@RequestMapping("/applet/owner")
public class OwnerController {
	@Autowired
	private OwnerFacade ownerFacade = null;

	/**
	 * 寄件人或是收件人资料添加
	 * 
	 * @param senderDto
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/add.do", method = RequestMethod.POST)
	@ResponseBody
	public ViewData ownerAdd(String openId, OwnerDto dto) throws Exception {
		ownerFacade.addOwner(openId, dto);
		return ViewModelUtil.buildSuccess("添加成功");
	}

	/**
	 * 查询全部寄件人或是收件人
	 * @param senderDto
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/all.do", method = RequestMethod.POST)
	@ResponseBody
	public ViewData ownerAll(String openId, Integer ownerIsSender) throws Exception {
		List<OwnerDto> allOwner = ownerFacade.allOwner(openId, ownerIsSender);
		return ViewModelUtil.buildSuccessPage("成功", allOwner, allOwner.size());
	}

	/**
	 * 精确寄件人或是收件人
	 * 
	 * @param senderDto
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/query.do", method = RequestMethod.POST)
	@ResponseBody
	public ViewData ownerQuery(String openId, Integer ownerIsSender,Long ownerId) throws Exception {
		OwnerDto owner = ownerFacade.getOwner(openId, ownerId,ownerIsSender);
		return ViewModelUtil.buildSuccess(0, "成功", owner);
	}

	/**
	 * 寄件人或是收件人删除
	 * 
	 * @param senderDto
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/del.do", method = RequestMethod.POST)
	@ResponseBody
	public ViewData ownerDel(String openId, @RequestParam("ownerId") Long ownerId,@RequestParam("ownerIsSender") Integer ownerIsSender) throws Exception {
		ownerFacade.delOwner(openId, ownerId, ownerIsSender);
		return ViewModelUtil.buildSuccess("成功");
	}

}
